/** @file    EncodersXmlQt_Core.cpp
 *  @author  Alessandro Polo
 *  @version $Id: EncodersXmlQt_Core.cpp 2832 2010-08-02 22:53:46Z alex $
 *  @brief
 * The header for this class can be found in EncodersXmlQt_Core.h, check that file
 * for class description.
 ****************************************************************************/
/* Copyright (c) 2007-2010, WOSH - Wide Open Smart Home 
 * by Alessandro Polo - OpenSmartHome.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSmartHome.com WOSH nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/
 
 #include <framework/persistence/qt/EncodersXmlQt_Core.h>

 #include <core/ObjectAllocator.h>


namespace wosh {
 namespace persistence {
  namespace qt {

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 WOSH_ENCODER_XML_Qt_BIND(wosh::persistence::qt::EncoderXml_Qt_BundleRequirement, "wosh::BundleRequirement", 0.0, _static_EncoderXml_Qt_BundleRequirement )

WRESULT EncoderXml_Qt_BundleRequirement::serializeTo( const wosh::BundleRequirement* object, QDomDocument& doc, QDomElement& contNode, int encoder_options ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	WRESULT ret = EncoderXml_Qt_ObjectTypeInfo::serializeTo(&object->getClassInfo(), doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeLong( "locationHopsMax", object->getLocationHopsMax(), doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeLong( "reqScope", object->getScopes(), doc, contNode, encoder_options );
	return ret;
 }

WRESULT EncoderXml_Qt_BundleRequirement::deserializeFrom( wosh::BundleRequirement* object, const QDomElement& contNode ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	WRESULT ret = EncoderXml_Qt_ObjectTypeInfo::deserializeFrom(&object->getClassInfo(), contNode );
	object->setLocationHopsMax( EncoderBaseXmlQt::deserializeLong( "locationHopsMax", -1, contNode ) );
	object->setScopes( EncoderBaseXmlQt::deserializeLong( "reqScope", (int)Bundle::STATE_UNKNOWN, contNode ) );
	return ret;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 WOSH_ENCODER_XML_Qt_BIND(wosh::persistence::qt::EncoderXml_Qt_BundleRequirements, "wosh::BundleRequirements", 0.0, _static_EncoderXml_Qt_BundleRequirements )

WRESULT EncoderXml_Qt_BundleRequirements::serializeTo( const wosh::BundleRequirements* object, QDomDocument& doc, QDomElement& contNode, int encoder_options ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	WRESULT ret = EncoderBaseXmlQt::serializeListT<BundleRequirement, EncoderXml_Qt_BundleRequirement>(*object, doc, contNode, encoder_options);
	return ret;
 }

WRESULT EncoderXml_Qt_BundleRequirements::deserializeFrom( wosh::BundleRequirements* object, const QDomElement& contNode ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	WRESULT ret = EncoderBaseXmlQt::deserializeListT<BundleRequirement, EncoderXml_Qt_BundleRequirement>(*object, contNode);
	return ret;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 WOSH_ENCODER_XML_Qt_BIND(wosh::persistence::qt::EncoderXml_Qt_Communicator, "wosh::Communicator", 0.0, _static_EncoderXml_Qt_Communicator )

WRESULT EncoderXml_Qt_Communicator::serializeTo( const wosh::Communicator* object, QDomDocument& doc, QDomElement& contNode, int encoder_options ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	WRESULT ret = EncoderXml_Qt_Object::serializeTo(object, doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeLong( "channelTypes", object->getChannelTypes(), doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeLong( "channelLink", (int)object->getChannelLink(), doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeDouble( "cost", object->getCost(), doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeLong( "priority", object->getPriority(), doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeLong( "reliability", object->getReliability(), doc, contNode, encoder_options );
	return WRET_OK;
 }

WRESULT EncoderXml_Qt_Communicator::deserializeFrom( wosh::Communicator* object, const QDomElement& contNode ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	WRESULT ret = EncoderXml_Qt_Object::deserializeFrom(object, contNode );
	object->setChannelTypes( EncoderBaseXmlQt::deserializeLong( "channelTypes", (int)Communicator::DUPLEX_UNKNOWN, contNode ) );
	object->setChannelLink( (Communicator::CHANNEL_LINK)EncoderBaseXmlQt::deserializeLong( "channelLink", (int)Communicator::LINK_UNKNOWN, contNode ) );
	object->setCost( EncoderBaseXmlQt::deserializeDouble( "cost", 0.0, contNode ) );
	object->setPriority( EncoderBaseXmlQt::deserializeLong( "priority", 0, contNode ) );
	object->setReliability( EncoderBaseXmlQt::deserializeLong( "reliability", 0, contNode ) );
	return WRET_OK;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 WOSH_ENCODER_XML_Qt_BIND(wosh::persistence::qt::EncoderXml_Qt_DeprecatedFunctionInfo, "wosh::DeprecatedFunctionInfo", 0.0, _static_EncoderXml_Qt_DeprecatedFunctionInfo )

WRESULT EncoderXml_Qt_DeprecatedFunctionInfo::serializeTo( const wosh::DeprecatedFunctionInfo* object, QDomDocument& doc, QDomElement& contNode, int encoder_options ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	EncoderBaseXmlQt::serializeString( "OldFunctionName", object->getOldFunctionName(), doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeString( "NewFunctionName", object->getNewFunctionName(), doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeString( "flename", object->getFileName(), doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeLong( "fileline", object->getFileLine(), doc, contNode, encoder_options );
	return WRET_OK;
 }

WRESULT EncoderXml_Qt_DeprecatedFunctionInfo::deserializeFrom( wosh::DeprecatedFunctionInfo* object, const QDomElement& contNode ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	return WRET_OK;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 WOSH_ENCODER_XML_Qt_BIND(wosh::persistence::qt::EncoderXml_Qt_Fact, "wosh::Fact", 0.0, _static_EncoderXml_Qt_Fact )

WRESULT EncoderXml_Qt_Fact::serializeTo( const wosh::Fact* object, QDomDocument& doc, QDomElement& contNode, int encoder_options ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	EncoderBaseXmlQt::serializeString( "event", object->getEvent(), doc, contNode, encoder_options );
	if ( !object->hasData() ) return WRET_OK;
	QDomElement dataNode = doc.createElement("data"); contNode.appendChild(dataNode);
	return EncoderProtocolXmlQt::serializeTo( object->getData(), doc, dataNode, encoder_options );
 }

WRESULT EncoderXml_Qt_Fact::deserializeFrom( wosh::Fact* object, const QDomElement& contNode ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	WRESULT ret = WRET_OK;
	object->setEvent( EncoderBaseXmlQt::deserializeString( "event", "", contNode ) );
	QDomElement dataNode = contNode.namedItem("data").toElement();
	if ( !dataNode.isNull() ) {
		ISerializable* data = EncoderProtocolXmlQt::deserializeFrom( dataNode, &ret );
		object->setData(data);
	 }
	return ret;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 WOSH_ENCODER_XML_Qt_BIND(wosh::persistence::qt::EncoderXml_Qt_InterfacesProvider, "wosh::InterfacesProvider", 0.0, _static_EncoderXml_Qt_InterfacesProvider )

WRESULT EncoderXml_Qt_InterfacesProvider::serializeTo( const wosh::InterfacesProvider* object, QDomDocument& doc, QDomElement& contNode, int encoder_options ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	WRESULT ret = 1;//EncoderBaseXmlQt::serializeMapT<std::string, ObjectTypeInfo, EncoderXml_Qt_ObjectTypeInfo, EncoderXml_Qt_Variant>(*object, doc, contNode, encoder_options);
	return ret;
 }

WRESULT EncoderXml_Qt_InterfacesProvider::deserializeFrom( wosh::InterfacesProvider* object, const QDomElement& contNode ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	WRESULT ret = 1;//EncoderBaseXmlQt::deserializeMapT<std::string, ObjectTypeInfo, EncoderXml_Qt_ObjectTypeInfo, EncoderXml_Qt_Variant>( *object, contNode, NULL );
	return ret;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 WOSH_ENCODER_XML_Qt_BIND(wosh::persistence::qt::EncoderXml_Qt_List, "wosh::List", 0.0, _static_EncoderXml_Qt_List )

WRESULT EncoderXml_Qt_List::serializeTo( const wosh::List* object, QDomDocument& doc, QDomElement& contNode, int encoder_options ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	WRESULT ret = WRET_OK; WRESULT ret_t = WRET_OK;
	object->transactionBeginRead();
	EncoderBaseXmlQt::serializeLong( "size", object->size(), doc, contNode, true );
	wosh::List::ConstIterator it;
	const wosh::List::ConstIterator it_end = object->end();
	for (it=object->begin(); it!=it_end; ++it) {
		QDomElement itemNode = doc.createElement("li");
		if ( *it == NULL ) ret_t = WRET_OK;
		else ret_t = EncoderProtocolXmlQt::serializeTo( *it, doc, itemNode, encoder_options );
		if ( WSUCCEEDED(ret_t) ) contNode.appendChild(itemNode);
		ret += ret_t;
	}
	object->transactionEnd();
	return ret;
 }

WRESULT EncoderXml_Qt_List::deserializeFrom( wosh::List* object, const QDomElement& contNode ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	WRESULT ret = WRET_OK;
	object->reserve( EncoderBaseXmlQt::deserializeLong( "size", 0, contNode ) );
	QDomNodeList nodeList = contNode.childNodes();
	for( unsigned int col=0; col<nodeList.length(); ++col ) {
		QDomElement itemNode = nodeList.item(col).toElement();
		if ( itemNode.tagName() != "li" ) continue;
		ISerializable* c_obj = EncoderProtocolXmlQt::deserializeFrom( itemNode );
		object->push_back( c_obj );
	 }
	return ret;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 WOSH_ENCODER_XML_Qt_BIND(wosh::persistence::qt::EncoderXml_Qt_Message, "wosh::Message", 0.0, _static_EncoderXml_Qt_Message )

WRESULT EncoderXml_Qt_Message::serializeTo( const wosh::Message* object, QDomDocument& doc, QDomElement& contNode, int encoder_options ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	WRESULT ret = WRET_OK;
	EncoderBaseXmlQt::serializeInt64( "id", object->getID(), doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeInt64( "timestamp", object->getTimestamp(), doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeLong( "priority", (int)object->getPriority(), doc, contNode, encoder_options );
	if ( !isCompact(encoder_options) || object->getTTL() != 0 )
		EncoderBaseXmlQt::serializeLong( "TTL", object->getTTL(), doc, contNode, encoder_options );
	if ( !isCompact(encoder_options) || object->getReferenceID() != 0 )
		EncoderBaseXmlQt::serializeInt64( "ref-id", object->getReferenceID(), doc, contNode, encoder_options );
	QDomElement sourceNode = doc.createElement("source"); contNode.appendChild(sourceNode);
	ret += EncoderXml_Qt_URI::serializeTo( &object->getSource(), doc, sourceNode, encoder_options);
	EncoderBaseXmlQt::serializeString( "bus", object->getSourceBus(), doc, sourceNode, true );
	if ( !object->getSourceUUID().empty() )
		EncoderBaseXmlQt::serializeString( "uuid", object->getSourceUUID(), doc, sourceNode, true );
	QDomElement destinationNode = doc.createElement("destination"); contNode.appendChild(destinationNode);
	ret += EncoderXml_Qt_URI::serializeTo( &object->getDestination(), doc, destinationNode, encoder_options);
	EncoderBaseXmlQt::serializeString( "bus", object->getDestinationBus(), doc, destinationNode, true );
	if ( !object->getDestinationUUID().empty() )
		EncoderBaseXmlQt::serializeString( "uuid", object->getDestinationUUID(), doc, destinationNode, true );
	if ( !object->isEmpty() ) {
		QDomElement contentNode = doc.createElement("content"); contNode.appendChild(contentNode);
		ret += EncoderProtocolXmlQt::serializeTo( object->getContent(), doc, contentNode, encoder_options);
	 }
	if ( object->hasNetworkForwarders() ) {
		QDomElement forwardersNode = doc.createElement("forwarders"); contNode.appendChild(forwardersNode);
		ret += EncoderProtocolXmlQt::serializeTo( object->getNetworkForwarders(), doc, forwardersNode, encoder_options);
	 }
	if ( object->hasSecurityToken() ) {
		QDomElement securityNode = doc.createElement("security"); contNode.appendChild(securityNode);
		ret += EncoderProtocolXmlQt::serializeTo( object->getSecurityToken(), doc, securityNode, encoder_options);
	 }
	return ret;
 }

WRESULT EncoderXml_Qt_Message::deserializeFrom( wosh::Message* object, const QDomElement& contNode ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	WRESULT ret = WRET_OK;
	int64 id = EncoderBaseXmlQt::deserializeInt64( "id", 0, contNode );
	int64 ref_id = EncoderBaseXmlQt::deserializeInt64( "ref-id", 0, contNode );
	int64 ts = EncoderBaseXmlQt::deserializeInt64( "timestamp", 0, contNode );
	message_assign( object, id, ref_id, ts);
	QDomElement sourceNode = contNode.namedItem("source").toElement();
	if ( !sourceNode.isNull() ) {
		ret += EncoderXml_Qt_URI::deserializeFrom( &object->getSource(), sourceNode);
		if ( sourceNode.hasAttribute("bus") )
			object->setSourceBus( EncoderBaseXmlQt::deserializeString( "bus", "", sourceNode ) );
		if ( sourceNode.hasAttribute("uuid") )
			object->setSourceUUID( EncoderBaseXmlQt::deserializeString( "uuid", "", sourceNode ) );
	 }
	QDomElement destinationNode = contNode.namedItem("destination").toElement();
	if ( !destinationNode.isNull() ) {
		ret += EncoderXml_Qt_URI::deserializeFrom( &object->getDestination(), destinationNode);
		if ( destinationNode.hasAttribute("bus") )
			object->setDestinationBus( EncoderBaseXmlQt::deserializeString( "bus", "", destinationNode ) );
		if ( destinationNode.hasAttribute("uuid") )
			object->setDestinationUUID( EncoderBaseXmlQt::deserializeString( "uuid", "", destinationNode ) );
	 }
	QDomElement contentNode = contNode.namedItem("content").toElement();
	if ( !contentNode.isNull() ) {
		wosh::MessageContent* data = EncoderProtocolXmlQt::deserializeFrom<wosh::MessageContent>( contentNode, &ret );
		object->setContent(data);
	 }
	QDomElement forwardersNode = contNode.namedItem("forwarders").toElement();
	if ( !forwardersNode.isNull() ) {
		wosh::MessageNetworkForwarding* data = EncoderProtocolXmlQt::deserializeFrom<wosh::MessageNetworkForwarding>( forwardersNode, &ret );
		object->setNetworkForwarders(data);
	 }
	QDomElement securityNode = contNode.namedItem("security").toElement();
	if ( !securityNode.isNull() ) {
		wosh::SecurityToken* data = EncoderProtocolXmlQt::deserializeFrom<wosh::SecurityToken>( securityNode, NULL);//&ret );
		object->setSecurityToken(data);
	 }
	return ret;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 WOSH_ENCODER_XML_Qt_BIND(wosh::persistence::qt::EncoderXml_Qt_MessageNetworkForwarding, "wosh::MessageNetworkForwarding", 0.0, _static_EncoderXml_Qt_MessageNetworkForwarding )

WRESULT EncoderXml_Qt_MessageNetworkForwarding::serializeTo( const wosh::MessageNetworkForwarding* object, QDomDocument& doc, QDomElement& contNode, int ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	std::vector<wosh::MessageNetworkForwarder>::const_iterator it;
	for ( it=object->getHosts().begin(); it!=object->getHosts().end(); ++it ) {
		QDomElement forwNode = doc.createElement("forwarder"); contNode.appendChild(forwNode);
		forwNode.appendChild( doc.createTextNode( QString((*it).name.c_str()) ) );
		forwNode.setAttribute("timestamp", QString::number((*it).timestamp) );
	 }
	return WRET_OK;
 }

WRESULT EncoderXml_Qt_MessageNetworkForwarding::deserializeFrom( wosh::MessageNetworkForwarding* object, const QDomElement& contNode ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	QDomNodeList nodesList = contNode.childNodes();
	for( unsigned int j=0; j<nodesList.length(); ++j ) {
		QDomElement childNode = nodesList.item(j).toElement();
		if ( childNode.text().isEmpty() ) continue;
		MessageNetworkForwarder mnf;
		mnf.name = std::string( childNode.text().toLatin1().data() );
		mnf.timestamp = childNode.attribute("timestamp").toLong();
		object->getHosts().push_back(mnf);
	 }
	return WRET_OK;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 WOSH_ENCODER_XML_Qt_BIND(wosh::persistence::qt::EncoderXml_Qt_Notification, "wosh::Notification", 0.0, _static_EncoderXml_Qt_Notification )

WRESULT EncoderXml_Qt_Notification::serializeTo( const wosh::Notification* object, QDomDocument& doc, QDomElement& contNode, int encoder_options ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	EncoderBaseXmlQt::serializeLong( "id", object->getID(), doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeLong( "flow-id", object->getFlowID(), doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeLong( "timestamp", object->getTimeStamp(), doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeLong( "priority", (int)object->getPriority(), doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeLong( "protocol", (int)object->getProtocol(), doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeString( "language", object->getLanguage(), doc, contNode, true );
	EncoderBaseXmlQt::serializeLong( "read-timestamp", object->getReadTimeStamp(), doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeLong( "sent-timestamp", object->getSentTimeStamp(), doc, contNode, encoder_options );
	QDomElement sender_node = doc.createElement("sender"); contNode.appendChild(sender_node);
	EncoderBaseXmlQt::serializeString( "id", object->getSender_ID(), doc, sender_node, true );
	EncoderBaseXmlQt::serializeString( "user", object->getSender_User(), doc, sender_node, true );
	QDomElement recipent_node = doc.createElement("recipent"); contNode.appendChild(recipent_node);
	EncoderBaseXmlQt::serializeString( "id", object->getRecipent_ID(), doc, recipent_node, true );
	EncoderBaseXmlQt::serializeString( "user", object->getRecipent_User(), doc, recipent_node, true );
	EncoderBaseXmlQt::serializeString( "group", object->getRecipent_Group(), doc, recipent_node, true );
	return WRET_OK;
 }

WRESULT EncoderXml_Qt_Notification::deserializeFrom( wosh::Notification* object, const QDomElement& contNode ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
// FRIEND BUG	object->setID( EncoderBaseXmlQt::deserialize( "id", 0, contNode ) );
	object->setFlowID( EncoderBaseXmlQt::deserializeLong( "flow-id", 0, contNode ) );
	object->setTimeStamp( EncoderBaseXmlQt::deserializeLong( "timestamp", 0, contNode ) );
	object->setPriority( (Notification::PRIORITY)EncoderBaseXmlQt::deserializeLong( "priority", (int)Notification::PRIORITY_UNKNOWN, contNode ) );
	object->setProtocol( (Notification::PROTOCOL)EncoderBaseXmlQt::deserializeLong( "protocol", (int)Notification::PROTOCOL_UNKNOWN, contNode ) );
	object->setLanguage( EncoderBaseXmlQt::deserializeString( "language", "", contNode ) );
	object->setRead( (bool)EncoderBaseXmlQt::deserializeLong( "read-timestamp", 0, contNode ), EncoderBaseXmlQt::deserializeLong( "read-timestamp", 0, contNode ) );
	object->setSent( (bool)EncoderBaseXmlQt::deserializeLong( "sent-timestamp", 0, contNode ), EncoderBaseXmlQt::deserializeLong( "sent-timestamp", 0, contNode ) );
	QDomElement sender_node = contNode.namedItem("sender").toElement();
	if ( !sender_node.isNull() ) {
		object->setSender_ID( EncoderBaseXmlQt::deserializeString( "id", "", sender_node ) );
		object->setSender_User( EncoderBaseXmlQt::deserializeString( "user", "", sender_node ) );
	 }
	QDomElement recipent_node = contNode.namedItem("recipent").toElement();
	if ( !recipent_node.isNull() ) {
		object->setRecipent_ID( EncoderBaseXmlQt::deserializeString( "id", "", recipent_node ) );
		object->setRecipent_User( EncoderBaseXmlQt::deserializeString( "user", "", recipent_node ) );
		object->setRecipent_Group( EncoderBaseXmlQt::deserializeString( "group", "", recipent_node ) );
	 }
	return WRET_OK;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 WOSH_ENCODER_XML_Qt_BIND(wosh::persistence::qt::EncoderXml_Qt_Object, "wosh::Object", 0.0, _static_EncoderXml_Qt_Object )

WRESULT EncoderXml_Qt_Object::serializeTo( const wosh::Object* object, QDomDocument& doc, QDomElement& contNode, int encoder_options ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	WRESULT ret = WRET_OK;
	EncoderBaseXmlQt::serializeString( "name", object->getName(), doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeString( "uuid", object->getEntityID(), doc, contNode, encoder_options );
	if ( !isCompact(encoder_options) || contNode.tagName() != object->getClassName() )
		EncoderBaseXmlQt::serializeString( "classname", object->getClassName(), doc, contNode, true );
	if ( isCompact(encoder_options) ) {
		EncoderBaseXmlQt::serializeString( "uri", object->getURI().toString(), doc, contNode, true );
	 }
	else {
		QDomElement uri_node = doc.createElement("uri"); contNode.appendChild(uri_node);
		ret += EncoderXml_Qt_URI::serializeTo(&object->getURI(), doc, uri_node, encoder_options );
	 }
	if ( !isCompact(encoder_options) || !object->getPermission().isEmpty() ) {
		if ( isCompact(encoder_options) )
			ret += EncoderXml_Qt_Permission::serializeTo(&object->getPermission(), doc, contNode, true );
		else {
			QDomElement permNode = doc.createElement("permission"); contNode.appendChild(permNode);
			ret += EncoderXml_Qt_Permission::serializeTo(&object->getPermission(), doc, permNode, true );
		 }
	 }
	return ret;
 }

WRESULT EncoderXml_Qt_Object::deserializeFrom( wosh::Object* object, const QDomElement& contNode ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	WRESULT ret = WRET_OK;
	object->setName( EncoderBaseXmlQt::deserializeString( "name", "", contNode ) );
	std::string uuid = EncoderBaseXmlQt::deserializeString( "uuid", "", contNode );
	if ( !uuid.empty() )
		object_assign( object, uuid );
	QDomElement uri_node = contNode.namedItem("uri").toElement();
	if ( !uri_node.isNull() )
		ret += EncoderXml_Qt_URI::deserializeFrom(&object->getURI(), uri_node );
	else if ( contNode.hasAttribute("uri") )
		object->getURI().fromString( contNode.attribute("uri").toLatin1().data() );
	Permission perm;
	QDomElement perm_node = contNode.namedItem("permission").toElement();
	if ( perm_node.isNull() )
		EncoderXml_Qt_Permission::deserializeFrom(&perm, contNode );
	else
		ret += EncoderXml_Qt_Permission::deserializeFrom(&perm, perm_node );
	object->setPermission(perm);
	return ret;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 WOSH_ENCODER_XML_Qt_BIND(wosh::persistence::qt::EncoderXml_Qt_ObjectTypeInfo, "wosh::ObjectTypeInfo", 0.0, _static_EncoderXml_Qt_ObjectTypeInfo )

WRESULT EncoderXml_Qt_ObjectTypeInfo::serializeTo( const wosh::ObjectTypeInfo* object, QDomDocument& doc, QDomElement& contNode, int encoder_options ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	EncoderBaseXmlQt::serializeString( "name", object->name, doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeString( "parent", object->parent, doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeDouble( "version", object->version, doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeBool( "allocable", object->allocable, doc, contNode, encoder_options );
	return WRET_OK;
 }

WRESULT EncoderXml_Qt_ObjectTypeInfo::deserializeFrom( wosh::ObjectTypeInfo* object, const QDomElement& contNode ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	object->name = EncoderBaseXmlQt::deserializeString( "name", "", contNode );
	object->parent = EncoderBaseXmlQt::deserializeString( "parent", "", contNode );
	object->version = EncoderBaseXmlQt::deserializeDouble( "version", 0.0, contNode );
	object->allocable = EncoderBaseXmlQt::deserializeBool( "allocable", false, contNode );
	return WRET_OK;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 WOSH_ENCODER_XML_Qt_BIND(wosh::persistence::qt::EncoderXml_Qt_Permission, "wosh::Permission", 0.0, _static_EncoderXml_Qt_Permission )

WRESULT EncoderXml_Qt_Permission::serializeTo( const wosh::Permission* object, QDomDocument& doc, QDomElement& contNode, int encoder_options ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	EncoderBaseXmlQt::serializeString( "owner", object->getOwner(), doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeString( "group", object->getGroup(), doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeString( "mask", object->getMask(), doc, contNode, encoder_options );
	return WRET_OK;
 }

WRESULT EncoderXml_Qt_Permission::deserializeFrom( wosh::Permission* object, const QDomElement& contNode ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	object->setOwner( EncoderBaseXmlQt::deserializeString( "owner", "", contNode ) );
	object->setGroup( EncoderBaseXmlQt::deserializeString( "group", "", contNode ) );
	object->setMask( EncoderBaseXmlQt::deserializeString( "mask", "", contNode ) );
	return WRET_OK;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 WOSH_ENCODER_XML_Qt_BIND(wosh::persistence::qt::EncoderXml_Qt_ProfileInfo, "wosh::ProfileInfo", 0.0, _static_EncoderXml_Qt_ProfileInfo )

WRESULT EncoderXml_Qt_ProfileInfo::serializeTo( const wosh::ProfileInfo* object, QDomDocument& doc, QDomElement& contNode, int encoder_options ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	EncoderBaseXmlQt::serializeString( "name", object->getName(), doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeInt64( "accessCount", object->getAccessCount(), doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeLong( "concurrentCount", object->getConcurrentCount(), doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeString( "parentClass", object->getParentClass(), doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeString( "parentName", object->getParentName(), doc, contNode, encoder_options );
	return WRET_OK;
 }

WRESULT EncoderXml_Qt_ProfileInfo::deserializeFrom( wosh::ProfileInfo* object, const QDomElement& contNode ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	return WRET_OK;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 WOSH_ENCODER_XML_Qt_BIND(wosh::persistence::qt::EncoderXml_Qt_Property, "wosh::Property", 0.0, _static_EncoderXml_Qt_Property )

WRESULT EncoderXml_Qt_Property::serializeTo( const wosh::Property* object, QDomDocument& doc, QDomElement& contNode, int encoder_options ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	WRESULT ret = WRET_OK;
	EncoderBaseXmlQt::serializeString( "key", object->getKey(), doc, contNode, encoder_options );
	if ( isCompact(encoder_options) )
		ret += EncoderXml_Qt_Variant::serializeTo(&object->getValue(), doc, contNode, true );
	else {
		QDomElement valueNode = doc.createElement("value"); contNode.appendChild(valueNode);
		ret += EncoderXml_Qt_Variant::serializeTo(&object->getValue(), doc, valueNode, true );
	 }
	if ( !isCompact(encoder_options) || !object->getPermission().isEmpty() ) {
		if ( isCompact(encoder_options) )
			ret += EncoderXml_Qt_Permission::serializeTo(&object->getPermission(), doc, contNode, true );
		else {
			QDomElement permNode = doc.createElement("permission"); contNode.appendChild(permNode);
			ret += EncoderXml_Qt_Permission::serializeTo(&object->getPermission(), doc, permNode, true );
		 }
	 }
	return ret;
 }

WRESULT EncoderXml_Qt_Property::deserializeFrom( wosh::Property* object, const QDomElement& contNode ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	WRESULT ret = WRET_OK;
	object->setKey( EncoderBaseXmlQt::deserializeString( "key", "", contNode ) );
	QDomElement value_node = contNode.namedItem("value").toElement();
	if ( !value_node.isNull() )
		ret += EncoderXml_Qt_Variant::deserializeFrom(&object->getValue(), value_node );
	else if ( contNode.hasAttribute("data") || contNode.hasAttribute("type") || !contNode.text().isEmpty() )
		ret += EncoderXml_Qt_Variant::deserializeFrom(&object->getValue(), contNode );
	QDomElement perm_node = contNode.namedItem("permission").toElement();
	if ( perm_node.isNull() )
		EncoderXml_Qt_Permission::deserializeFrom(&object->getPermission(), contNode );
	else
		ret += EncoderXml_Qt_Permission::deserializeFrom(&object->getPermission(), perm_node );
	return ret;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 WOSH_ENCODER_XML_Qt_BIND(wosh::persistence::qt::EncoderXml_Qt_PropertiesProvider, "wosh::PropertiesProvider", 0.0, _static_EncoderXml_Qt_PropertiesProvider )

WRESULT EncoderXml_Qt_PropertiesProvider::serializeTo( const wosh::PropertiesProvider* object, QDomDocument& doc, QDomElement& contNode, int encoder_options ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	WRESULT ret = WRET_OK; WRESULT ret_t = WRET_OK;
	wosh::PropertiesProvider::ConstIterator it;
	object->transactionBeginRead();
	const wosh::PropertiesProvider::ConstIterator it_end = object->getMap().end();
	for( it=object->getMap().begin(); it!=it_end; ++it ) {
		if ( it->second == NULL ) continue;
		if ( it->second->data == NULL ) continue;
		QDomElement dataNode = doc.createElement("property");
		ret_t = EncoderXml_Qt_Property::serializeTo( it->second->data, doc, dataNode, encoder_options );
		if ( WSUCCEEDED(ret_t) )
			contNode.appendChild(dataNode);
		ret += ret_t;
	 }
	object->transactionEnd();
	return ret;
 }

WRESULT EncoderXml_Qt_PropertiesProvider::deserializeFrom( wosh::PropertiesProvider* object, const QDomElement& contNode ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	WRESULT ret = WRET_OK; WRESULT ret_t = WRET_OK;
	Property prop_element;
	QDomNodeList nodesList = contNode.childNodes();
	for( unsigned int j=0; j<nodesList.length(); ++j ) {
		prop_element.clear();
		QDomElement childNode = nodesList.item(j).toElement();
		if ( childNode.tagName() != "property" ) continue;
		ret_t = EncoderXml_Qt_Property::deserializeFrom( &prop_element, childNode );
		if ( WSUCCEEDED(ret_t) )
			ret += object->set(prop_element);
	 }
	return ret;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 WOSH_ENCODER_XML_Qt_BIND(wosh::persistence::qt::EncoderXml_Qt_Request, "wosh::Request", 0.0, _static_EncoderXml_Qt_Request )

WRESULT EncoderXml_Qt_Request::serializeTo( const wosh::Request* object, QDomDocument& doc, QDomElement& contNode, int encoder_options ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	EncoderBaseXmlQt::serializeString( "method", object->getMethod(), doc, contNode, encoder_options );
	if ( !isCompact(encoder_options) || object->doOmitResponse() )
		EncoderBaseXmlQt::serializeBool( "omit-response", object->doOmitResponse(), doc, contNode, true );
	if ( !object->hasData() ) return WRET_OK;
	QDomElement dataNode = doc.createElement("data"); contNode.appendChild(dataNode);
	return EncoderProtocolXmlQt::serializeTo( object->getData(), doc, dataNode, encoder_options );
 }

WRESULT EncoderXml_Qt_Request::deserializeFrom( wosh::Request* object, const QDomElement& contNode ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	WRESULT ret = WRET_OK;
	object->setMethod( EncoderBaseXmlQt::deserializeString( "method", "", contNode ) );
	object->setOmitResponse( EncoderBaseXmlQt::deserializeBool( "omit-response", false, contNode ) );
	QDomElement dataNode = contNode.namedItem("data").toElement();
	if ( !dataNode.isNull() ) {
		ISerializable* data = EncoderProtocolXmlQt::deserializeFrom( dataNode, &ret );
		object->setData(data);
	 }
	return ret;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 WOSH_ENCODER_XML_Qt_BIND(wosh::persistence::qt::EncoderXml_Qt_Response, "wosh::Response", 0.0, _static_EncoderXml_Qt_Response )

WRESULT EncoderXml_Qt_Response::serializeTo( const wosh::Response* object, QDomDocument& doc, QDomElement& contNode, int encoder_options ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	EncoderBaseXmlQt::serializeString( "method", object->getMethod(), doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeLong( "return-value", object->getReturnValue(), doc, contNode, encoder_options );
	if ( !object->hasData() ) return WRET_OK;
	QDomElement dataNode = doc.createElement("data"); contNode.appendChild(dataNode);
	return EncoderProtocolXmlQt::serializeTo( object->getData(), doc, dataNode, encoder_options );
 }

WRESULT EncoderXml_Qt_Response::deserializeFrom( wosh::Response* object, const QDomElement& contNode ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	WRESULT ret = WRET_OK;
	object->setMethod( EncoderBaseXmlQt::deserializeString( "method", "", contNode ) );
	object->setReturnValue( EncoderBaseXmlQt::deserializeLong( "return-value", WRET_ERR_UNKNOWN, contNode ) );
	QDomElement dataNode = contNode.namedItem("data").toElement();
	if ( !dataNode.isNull() ) {
		ISerializable* data = EncoderProtocolXmlQt::deserializeFrom( dataNode, &ret );
		object->setData(data);
	 }
	return ret;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 WOSH_ENCODER_XML_Qt_BIND(wosh::persistence::qt::EncoderXml_Qt_ResourcePath, "wosh::ResourcePath", 0.0, _static_EncoderXml_Qt_ResourcePath )

WRESULT EncoderXml_Qt_ResourcePath::serializeTo( const wosh::ResourcePath* object, QDomDocument& doc, QDomElement& contNode, int encoder_options ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	EncoderBaseXmlQt::serializeString( "full-path", object->getPathFull(), doc, contNode, encoder_options );
	return WRET_OK;
 }

WRESULT EncoderXml_Qt_ResourcePath::deserializeFrom( wosh::ResourcePath* object, const QDomElement& contNode ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	bool done = object->set( EncoderBaseXmlQt::deserializeString( "full-path", "", contNode ) );
	if ( !done ) return WRET_ERR_INTERNAL;
	return WRET_OK;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 WOSH_ENCODER_XML_Qt_BIND(wosh::persistence::qt::EncoderXml_Qt_SecurityToken, "wosh::SecurityToken", 0.0, _static_EncoderXml_Qt_SecurityToken )

WRESULT EncoderXml_Qt_SecurityToken::serializeTo( const wosh::SecurityToken* object, QDomDocument& doc, QDomElement& contNode, int encoder_options ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	EncoderBaseXmlQt::serializeInt64( "id", object->getID(), doc, contNode, encoder_options );
	if ( !isCompact(encoder_options) || object->getVersion() != 0 )
		EncoderBaseXmlQt::serializeDouble( "version", object->getVersion(), doc, contNode, true );
	EncoderBaseXmlQt::serializeInt64( "timestamp", object->getTimeStamp(), doc, contNode, encoder_options );
	if ( !isCompact(encoder_options) || object->getTTL() != 0 )
		EncoderBaseXmlQt::serializeLong( "ttl", object->getTTL(), doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeString( "username", object->getUsername(), doc, contNode, encoder_options );
	QDomElement creatorNode = doc.createElement("creator"); contNode.appendChild(creatorNode);
	EncoderBaseXmlQt::serializeString( "uuid", object->getCreatorUUID(), doc, creatorNode, encoder_options );
	EncoderBaseXmlQt::serializeString( "hostname", object->getCreatorHostName(), doc, creatorNode, encoder_options );
	EncoderBaseXmlQt::serializeString( "provider", object->getProviderUUID(), doc, creatorNode, encoder_options );
	QDomElement targetNode = doc.createElement("target"); contNode.appendChild(targetNode);
	EncoderBaseXmlQt::serializeString( "uuid", object->getTargetUUID(), doc, targetNode, encoder_options );
	EncoderBaseXmlQt::serializeString( "hash", object->target_hash, doc, targetNode, encoder_options );
	QDomElement authenticatorNode = doc.createElement("authenticator"); contNode.appendChild(authenticatorNode);
	EncoderBaseXmlQt::serializeString( "name", object->getAuthenticatorName(), doc, authenticatorNode, encoder_options );
	if ( !isCompact(encoder_options) || object->getAuthenticatorVersion() != 0 )
		EncoderBaseXmlQt::serializeDouble( "version", object->getAuthenticatorVersion(), doc, authenticatorNode, encoder_options );
	EncoderBaseXmlQt::serializeLong( "mode", object->getAuthenticationMode(), doc, authenticatorNode, encoder_options );
	return WRET_OK;
 }

WRESULT EncoderXml_Qt_SecurityToken::deserializeFrom( wosh::SecurityToken* object, const QDomElement& contNode ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
// FRIEND BUG	object->setUser( EncoderBaseXmlQt::deserializeString( "user", "", contNode ) );
	object->token_id = EncoderBaseXmlQt::deserializeInt64( "id", 0, contNode );
	object->token_ts = EncoderBaseXmlQt::deserializeInt64( "timestamp", 0, contNode );
	object->ttl = EncoderBaseXmlQt::deserializeLong( "ttl", 0, contNode );
	object->user_name = EncoderBaseXmlQt::deserializeString( "username", "", contNode );
	QDomElement node_creator = contNode.namedItem("creator").toElement();
	if ( !node_creator.isNull() ) {
		object->creator_uuid = EncoderBaseXmlQt::deserializeString( "uuid", "", node_creator );
		object->host_name = EncoderBaseXmlQt::deserializeString( "hostname", "", node_creator );
		object->provider_uuid = EncoderBaseXmlQt::deserializeString( "provider", "", node_creator );
	 }
	QDomElement node_target = contNode.namedItem("target").toElement();
	if ( !node_target.isNull() ) {
		object->target_uuid = EncoderBaseXmlQt::deserializeString( "uuid", "", node_target );
		object->target_hash = EncoderBaseXmlQt::deserializeString( "hash", "", node_target );
	 }
	QDomElement node_authenticator = contNode.namedItem("authenticator").toElement();
	if ( !node_authenticator.isNull() ) {
		object->authenticator_classname = EncoderBaseXmlQt::deserializeString( "name", "", node_authenticator );
		object->authenticator_ver = EncoderBaseXmlQt::deserializeDouble( "version", 0.0, node_authenticator );
		object->authentication_mode = static_cast<wosh::SecurityToken::AUTHENTICATION_MODE>(EncoderBaseXmlQt::deserializeLong( "mode", wosh::SecurityToken::AUTH_UNKNOWN, node_authenticator ));
	 }
	return WRET_OK;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 WOSH_ENCODER_XML_Qt_BIND(wosh::persistence::qt::EncoderXml_Qt_SharedMemoryInfo, "wosh::SharedMemoryInfo", 0.0, _static_EncoderXml_Qt_SharedMemoryInfo )

WRESULT EncoderXml_Qt_SharedMemoryInfo::serializeTo( const wosh::SharedMemoryInfo* object, QDomDocument& doc, QDomElement& contNode, int encoder_options ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	EncoderBaseXmlQt::serializeLong( "id", object->id, doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeString( "kernel", object->kernel, doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeDouble( "seniority", object->seniority, doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeInt64( "clock", object->clock, doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeBool( "primary", object->primary, doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeLong( "mode", object->mode, doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeLong( "strategy", object->strategy, doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeLong( "propagation", object->propagation, doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeLong( "last-seen", object->lastSeen, doc, contNode, encoder_options );
	return WRET_OK;
 }

WRESULT EncoderXml_Qt_SharedMemoryInfo::deserializeFrom( wosh::SharedMemoryInfo* object, const QDomElement& contNode ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	object->id = EncoderBaseXmlQt::deserializeLong( "id", 0, contNode );
	object->kernel = EncoderBaseXmlQt::deserializeString( "kernel", "", contNode );
	object->seniority = EncoderBaseXmlQt::deserializeDouble( "seniority", 0, contNode );
	object->clock = EncoderBaseXmlQt::deserializeInt64( "clock", 0, contNode );
	object->primary = EncoderBaseXmlQt::deserializeBool( "primary", false, contNode );
	object->mode = (short)EncoderBaseXmlQt::deserializeLong( "mode", 0, contNode );
	object->strategy = (short)EncoderBaseXmlQt::deserializeLong( "strategy", 0, contNode );
	object->propagation = (short)EncoderBaseXmlQt::deserializeLong( "propagation", 0, contNode );
	object->lastSeen = EncoderBaseXmlQt::deserializeLong( "last-seen", 0, contNode );
	return WRET_OK;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 WOSH_ENCODER_XML_Qt_BIND(wosh::persistence::qt::EncoderXml_Qt_SystemError, "wosh::SystemError", 0.0, _static_EncoderXml_Qt_SystemError )

WRESULT EncoderXml_Qt_SystemError::serializeTo( const wosh::SystemError* object, QDomDocument& doc, QDomElement& contNode, int encoder_options ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	EncoderBaseXmlQt::serializeInt64( "id", object->getID(), doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeInt64( "timestamp", object->getTimeStamp(), doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeLong( "error-code", object->getErrorCode(), doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeString( "method", object->getMethod(), doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeString( "source-uri", object->getSource().toString(), doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeLong( "priority", static_cast<int>(object->getPriority()), doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeString( "description", object->getDescription(), doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeString( "context", object->getContext(), doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeString( "tips", object->getTips(), doc, contNode, encoder_options );
	return WRET_OK;
 }

WRESULT EncoderXml_Qt_SystemError::deserializeFrom( wosh::SystemError* object, const QDomElement& contNode ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	object->setID( EncoderBaseXmlQt::deserializeInt64( "id", 0, contNode ) );
	object->setTimestamp( EncoderBaseXmlQt::deserializeInt64( "timestamp", 0, contNode ) );
	object->setErrorCode( EncoderBaseXmlQt::deserializeLong( "error-code", 0, contNode ) );
	object->setMethod( EncoderBaseXmlQt::deserializeString( "method", "", contNode ) );
	object->getSource().fromString( EncoderBaseXmlQt::deserializeString( "source-uri", "", contNode ) );
	object->setPriority( static_cast<SystemError::ERROR_PRIORITY>(EncoderBaseXmlQt::deserializeLong( "priority", 0, contNode )) );
	object->setDescription( EncoderBaseXmlQt::deserializeString( "description", "", contNode ) );
	object->setContext( EncoderBaseXmlQt::deserializeString( "context", "", contNode ) );
	object->setTips( EncoderBaseXmlQt::deserializeString( "tips", "", contNode ) );
	return WRET_OK;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 WOSH_ENCODER_XML_Qt_BIND(wosh::persistence::qt::EncoderXml_Qt_Table, "wosh::Table", 0.0, _static_EncoderXml_Qt_Table )

WRESULT EncoderXml_Qt_Table::serializeTo( const wosh::Table* object, QDomDocument& doc, QDomElement& contNode, int encoder_options ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	WRESULT ret = WRET_OK; WRESULT ret_t = WRET_OK;
	EncoderBaseXmlQt::serializeString( "name", object->getTableName(), doc, contNode, true );
	EncoderBaseXmlQt::serializeLong( "rows", object->getRows(), doc, contNode, true );
	EncoderBaseXmlQt::serializeLong( "cols", object->getCols(), doc, contNode, true );
	if ( object->hasHeaderHorizontal() ) {
		QDomElement hHorizontalNode = doc.createElement("header-horizontal"); contNode.appendChild(hHorizontalNode);
		for (unsigned int col=0; col<object->getCols(); ++col) {
			QDomElement itemNode = doc.createElement("hh-item"); hHorizontalNode.appendChild(itemNode);
			const ISerializable* cItem = object->getHeaderHorizontal(col);
			if ( cItem == NULL ) continue;
			ret_t = EncoderProtocolXmlQt::serializeTo( cItem, doc, itemNode, encoder_options );
		 }
	 }
	if ( object->hasHeaderVertical() ) {
		QDomElement hVerticalNode = doc.createElement("header-vertical"); contNode.appendChild(hVerticalNode);
		for (unsigned int row=0; row<object->getRows(); ++row) {
			QDomElement itemNode = doc.createElement("hv-item"); hVerticalNode.appendChild(itemNode);
			const ISerializable* cItem = object->getHeaderVertical(row);
			if ( cItem == NULL ) continue;
			ret_t = EncoderProtocolXmlQt::serializeTo( cItem, doc, itemNode, encoder_options );
		 }
	 }
	QDomElement itemsNode = doc.createElement("table-items"); contNode.appendChild(itemsNode);
	for (unsigned int row=0; row<object->getRows(); ++row) {
		QDomElement rowNode = doc.createElement("trow"); itemsNode.appendChild(rowNode);
		if ( !isCompact(encoder_options) ) rowNode.setAttribute("row-index", row);
		for (unsigned int col=0; col<object->getCols(); ++col) {
			QDomElement rowColNode = doc.createElement("titem"); rowNode.appendChild(rowColNode);
			if ( !isCompact(encoder_options) ) rowColNode.setAttribute("col-index", col);
			const ISerializable* cItem = object->get(row, col);
			if ( cItem == NULL ) continue;
			ret_t = EncoderProtocolXmlQt::serializeTo( cItem, doc, rowColNode, encoder_options );
		 }
	 }
	return ret;
 }

WRESULT EncoderXml_Qt_Table::deserializeFrom( wosh::Table* object, const QDomElement& contNode ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	WRESULT ret = WRET_OK; WRESULT ret_t = WRET_OK;
	object->setTableName( EncoderBaseXmlQt::deserializeString( "name", "", contNode ) );
	unsigned int rows = EncoderBaseXmlQt::deserializeLong( "rows", 0, contNode );
	unsigned int cols = EncoderBaseXmlQt::deserializeLong( "cols", 0, contNode );
	object->alloc(rows, cols);
	QDomElement hHorizontalNode = contNode.namedItem("header-horizontal").toElement();
	if ( !hHorizontalNode.isNull() ) {
		object->allocHeaderHorizontal(true);
		QDomNodeList nodesList = hHorizontalNode.childNodes();
		for( unsigned int col=0; col<nodesList.length(); ++col ) {
			QDomElement childNode = nodesList.item(col).toElement();
			ISerializable* hItem = EncoderProtocolXmlQt::deserializeFrom( childNode, &ret_t );
			object->setHeaderHorizontal(hItem, col);
		 }
	 }
	QDomElement hHVerticalNode = contNode.namedItem("header-vertical").toElement();
	if ( !hHVerticalNode.isNull() ) {
		object->allocHeaderVertical(true);
		QDomNodeList nodesList = hHVerticalNode.childNodes();
		for( unsigned int row=0; row<nodesList.length(); ++row ) {
			QDomElement childNode = nodesList.item(row).toElement();
			ISerializable* hItem = EncoderProtocolXmlQt::deserializeFrom( childNode, &ret_t );
			object->setHeaderVertical(hItem, row);
		 }
	 }
	QDomElement itemsNode = contNode.namedItem("table-items").toElement();
	if ( !itemsNode.isNull() ) {
		QDomNodeList rowsList = itemsNode.childNodes();
		for( unsigned int row=0; row<rowsList.length(); ++row ) {
			QDomElement rowNode = rowsList.item(row).toElement();
			if ( rowNode.tagName() != "trow" ) continue;
			QDomNodeList colList = rowNode.childNodes();
			for( unsigned int col=0; col<colList.length(); ++col ) {
				QDomElement rowColNode = colList.item(col).toElement();
				ISerializable* hItem = EncoderProtocolXmlQt::deserializeFrom( rowColNode, &ret_t );
			//	if ( rowNode.hasAttribute("row-index") )
			//		object->set(hItem, rowNode.attribute("row-index").toInt(), col);
			//	else
					object->set(hItem, row, col);
			 }
		 }
	 }
	return ret;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 WOSH_ENCODER_XML_Qt_BIND(wosh::persistence::qt::EncoderXml_Qt_Tree, "wosh::Tree", 0.0, _static_EncoderXml_Qt_Tree )

WRESULT EncoderXml_Qt_Tree::serializeTo( const wosh::Tree* object, QDomDocument& doc, QDomElement& contNode, int encoder_options ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	EncoderBaseXmlQt::serializeString( "name", object->getTreeName(), doc, contNode, true );
	if ( !object->hasRoot() ) return WRET_OK;
	QDomElement rootNode = doc.createElement("root"); contNode.appendChild(rootNode);
	return EncoderXml_Qt_TreeNode::serializeTo( object->getRoot(), doc, rootNode, encoder_options );
 }

WRESULT EncoderXml_Qt_Tree::deserializeFrom( wosh::Tree* object, const QDomElement& contNode ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	WRESULT ret = WRET_OK;
	object->setTreeName( EncoderBaseXmlQt::deserializeString( "name", "", contNode ) );
	QDomElement rootNode = contNode.namedItem("root").toElement();
	if ( !rootNode.isNull() ) {
		TreeNode* rootTreeNode = new TreeNode(NULL);
		ret = EncoderXml_Qt_TreeNode::deserializeFrom( rootTreeNode, rootNode );
		object->setRoot(rootTreeNode);
	 }
	return ret;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 WOSH_ENCODER_XML_Qt_BIND(wosh::persistence::qt::EncoderXml_Qt_TreeNode, "wosh::TreeNode", 0.0, _static_EncoderXml_Qt_TreeNode )

WRESULT EncoderXml_Qt_TreeNode::serializeTo( const wosh::TreeNode* object, QDomDocument& doc, QDomElement& contNode, int encoder_options ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	WRESULT ret = WRET_OK; WRESULT ret_t = WRET_OK;
	if ( object->hasContent() ) {
		QDomElement dataNode = doc.createElement("content"); contNode.appendChild(dataNode);
		ret = EncoderProtocolXmlQt::serializeTo( object->getContent(), doc, dataNode, encoder_options);
	 }
	object->getChildren().transactionBeginRead();
	if ( !object->getChildren().isEmpty() ) {
		QDomElement childrenNode = doc.createElement("children"); contNode.appendChild(childrenNode);
		if ( !isCompact(encoder_options) ) childrenNode.setAttribute("size", object->getChildren().size() );
		TreeNodeT<ISerializable*>::ChildConstIterator it;
		const TreeNodeT<ISerializable*>::ChildConstIterator it_end = object->getChildren().end();
		for( it=object->getChildren().begin(); it!=it_end; ++it) {
			QDomElement childNode = doc.createElement("node"); childrenNode.appendChild(childNode);
			const wosh::TreeNode* cNode = dynamic_cast<const TreeNode*>(*it);
			ret_t = EncoderProtocolXmlQt::serializeTo( cNode, doc, childNode, encoder_options );
		 }
	 }
	object->getChildren().transactionEnd();
	return ret;
 }

WRESULT EncoderXml_Qt_TreeNode::deserializeFrom( wosh::TreeNode* object, const QDomElement& contNode ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	WRESULT ret = WRET_OK; WRESULT ret_t = WRET_OK;
	QDomElement dataNode = contNode.namedItem("content").toElement();
	if ( !dataNode.isNull() ) {
		ISerializable* contentData = EncoderProtocolXmlQt::deserializeFrom( dataNode );
		object->setContent(contentData);
	 }
	QDomElement childrenNode = contNode.namedItem("children").toElement();
	if ( !childrenNode.isNull() ) {
		object->getChildren().transactionBeginWrite();
		QDomNodeList nodesList = childrenNode.childNodes();
		for( unsigned int index=0; index<nodesList.length(); ++index ) {
			QDomElement childNode = nodesList.item(index).toElement();
			TreeNode* childTreeNode = new TreeNode(object);
			ret_t = EncoderXml_Qt_TreeNode::deserializeFrom( childTreeNode, childNode );
		 }
		object->getChildren().transactionEnd();
	 }
	return ret;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 WOSH_ENCODER_XML_Qt_BIND(wosh::persistence::qt::EncoderXml_Qt_URI, "wosh::URI", 0.0, _static_EncoderXml_Qt_URI )

WRESULT EncoderXml_Qt_URI::serializeTo( const wosh::URI* object, QDomDocument& doc, QDomElement& contNode, int encoder_options ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	if ( isCompact(encoder_options) )
		EncoderBaseXmlQt::serializeString( "uri", object->toString(), doc, contNode, true );
	else
		contNode.appendChild(doc.createTextNode( QString(object->toString().c_str()) ));
	return WRET_OK;
 }

WRESULT EncoderXml_Qt_URI::deserializeFrom( wosh::URI* object, const QDomElement& contNode ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	if ( !contNode.text().isEmpty() )
		object->fromString( contNode.text().toLatin1().data() );
	else if ( contNode.hasAttribute("uri") )
		object->fromString( EncoderBaseXmlQt::deserializeString( "uri", "", contNode ) );
	return WRET_OK;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 WOSH_ENCODER_XML_Qt_BIND(wosh::persistence::qt::EncoderXml_Qt_User, "wosh::User", 0.0, _static_EncoderXml_Qt_User )

WRESULT EncoderXml_Qt_User::serializeTo( const wosh::User* object, QDomDocument& doc, QDomElement& contNode, int encoder_options ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	WRESULT ret = EncoderXml_Qt_Object::serializeTo(object, doc, contNode, true );
	EncoderBaseXmlQt::serializeLong( "id", object->getID(), doc, contNode, true );
	QDomElement node_groups = doc.createElement("groups"); contNode.appendChild(node_groups);
	EncoderBaseXmlQt::serializeVectorString( object->getGroups(), doc, node_groups, true, "group");
	QDomElement node_properties = doc.createElement("properties"); contNode.appendChild(node_properties);
	ret += EncoderXml_Qt_PropertiesProvider::serializeTo(&object->getProperties(), doc, node_properties, encoder_options );
	return ret;
 }

WRESULT EncoderXml_Qt_User::deserializeFrom( wosh::User* object, const QDomElement& contNode ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	WRESULT ret = EncoderXml_Qt_Object::deserializeFrom(object, contNode );
	long id = EncoderBaseXmlQt::deserializeLong( "id", 0, contNode );
	if ( id != 0 )
		user_assign( object, id );
	QDomElement node_groups = contNode.namedItem("groups").toElement();
	EncoderBaseXmlQt::deserializeVectorString( object->getGroups(), node_groups, "group");
	QDomElement node_properties = contNode.namedItem("properties").toElement();
	if ( !node_properties.isNull() )
		ret += EncoderXml_Qt_PropertiesProvider::deserializeFrom(&object->getProperties(), node_properties );
	return ret;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 WOSH_ENCODER_XML_Qt_BIND(wosh::persistence::qt::EncoderXml_Qt_Variant, "wosh::Variant", 0.0, _static_EncoderXml_Qt_Variant )

WRESULT EncoderXml_Qt_Variant::serializeTo( const wosh::Variant* object, QDomDocument& doc, QDomElement& contNode, int encoder_options ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	EncoderBaseXmlQt::serializeString( "type", object->getTypeAsString(), doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeString( "data", object->toString(), doc, contNode, encoder_options );
	return WRET_OK;
 }

WRESULT EncoderXml_Qt_Variant::deserializeFrom( wosh::Variant* object, const QDomElement& contNode ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	object->clear();
	QString data;
	QDomElement dataNode = contNode.namedItem("data").toElement();
	if ( dataNode.isNull() && contNode.hasAttribute("data") )
		data = contNode.attribute("data");
	else if ( !dataNode.text().isEmpty() )
		data = dataNode.text();
	else
		data = contNode.text();
	Variant::DATA_TYPE dType = Variant::EMPTY;
	QDomElement typeNode = contNode.namedItem("type").toElement();
	if ( typeNode.isNull() && contNode.hasAttribute("type") )
		dType = Variant::getTypeFromString( contNode.attribute("type").toLatin1().data() );
	else if ( !typeNode.text().isEmpty() )
		dType = Variant::getTypeFromString( typeNode.text().toLatin1().data() );
	object->fromString( data.toLatin1().data(), dType );
	return WRET_OK;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 WOSH_ENCODER_XML_Qt_BIND(wosh::persistence::qt::EncoderXml_Qt_WoshHost, "wosh::WoshHost", 0.0, _static_EncoderXml_Qt_WoshHost )

WRESULT EncoderXml_Qt_WoshHost::serializeTo( const wosh::WoshHost* object, QDomDocument& doc, QDomElement& contNode, int encoder_options ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	WRESULT ret = EncoderXml_Qt_Object::serializeTo(object, doc, contNode, true );
	EncoderBaseXmlQt::serializeLong( "protocol", (long)object->getDiscoveryProtocolVersion(), doc, contNode, encoder_options );
	EncoderBaseXmlQt::serializeLong( "last-seen", object->getSeen(), doc, contNode, encoder_options );
	QDomElement discovery_node = doc.createElement("discovery"); contNode.appendChild(discovery_node);
	EncoderBaseXmlQt::serializeString( "source", object->getDiscoverySource(), doc, discovery_node, encoder_options );
	EncoderBaseXmlQt::serializeString( "bind-address", object->getDiscoveryBindAddress(), doc, discovery_node, encoder_options );
	EncoderBaseXmlQt::serializeLong( "notify-frequency", object->getNotifyFrequency(), doc, discovery_node, encoder_options );
	EncoderBaseXmlQt::serializeLong( "kernel-state", (long)object->getKernelState(), doc, contNode, encoder_options );
	QDomElement node_protocols = doc.createElement("protocols"); contNode.appendChild(node_protocols);
	EncoderBaseXmlQt::serializeVectorString( object->getProtocols(), doc, node_protocols, true, "protocol");
	QDomElement node_neighbours = doc.createElement("neighbours"); contNode.appendChild(node_neighbours);
	EncoderBaseXmlQt::serializeMapStringLong( object->getNeighbours(), doc, node_neighbours, true, "", "timestamp");
	QDomElement node_connections = doc.createElement("connections"); contNode.appendChild(node_connections);
	EncoderBaseXmlQt::serializeMapStringLong( object->getConnections(), doc, node_connections, true, "connection", "channel-id");
	return ret;
 }

WRESULT EncoderXml_Qt_WoshHost::deserializeFrom( wosh::WoshHost* object, const QDomElement& contNode ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	WRESULT ret = EncoderXml_Qt_Object::deserializeFrom(object, contNode );
	object->setDiscoveryProtocolVersion( EncoderBaseXmlQt::deserializeLong( "protocol", 0, contNode ) );
	object->setSeen( EncoderBaseXmlQt::deserializeLong( "last-seen", 0, contNode ) );
	QDomElement node_discovery = contNode.namedItem("discovery").toElement();
	if ( !node_discovery.isNull() ) {
		object->setDiscoverSource( EncoderBaseXmlQt::deserializeString( "source", "", node_discovery ) );
		object->setDiscoveryBindAddress( EncoderBaseXmlQt::deserializeString( "bind-address", "", node_discovery ) );
		object->setNotifyFrequency( EncoderBaseXmlQt::deserializeLong( "notify-frequency", 0, node_discovery ) );
	 }
	object->setKernelState( EncoderBaseXmlQt::deserializeLong( "kernel-state", 0, contNode ) );
	QDomElement node_protocols = contNode.namedItem("protocols").toElement();
	EncoderBaseXmlQt::deserializeVectorString( object->getProtocols(), node_protocols, "protocol");
	QDomElement node_neighbours = contNode.namedItem("neighbours").toElement();
	EncoderBaseXmlQt::deserializeMapStringLong( object->getNeighbours(), node_neighbours, "", "timestamp");
	QDomElement node_connections = contNode.namedItem("connections").toElement();
	EncoderBaseXmlQt::deserializeMapStringLong( object->getConnections(), node_connections, "", "channel-id");
	return ret;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

  }; // namespace qt
 }; // namespace persistence
}; // namespace wosh
